package com.p7.notepad.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.p7.notepad.R;
import com.p7.notepad.adapter.SwitchUserAdapter;
import com.p7.notepad.app.BaseActivity;
import com.p7.notepad.bean.User;
import com.p7.notepad.tools.Storage;
import com.tools.s7.manager.AppManager;
import com.tools.s7.recycler.listener.Recycler;
import com.tools.s7.recycler.utils.RecyclerHelper;

import butterknife.BindView;
import butterknife.OnClick;

public class SwitchUserActivity extends BaseActivity {

    @BindView(R.id.switch_user_list)
    RecyclerView mList;

    private RecyclerHelper mHelper;

    @Override
    public int getLayoutId() {
        return R.layout.activity_switch_user;
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        mHelper = new RecyclerHelper.Builder<User>()
                .setRecycler(mList, new GridLayoutManager(this, 2))
                .setAdapter(new SwitchUserAdapter())
                .setItemClick(new Recycler.OnItemClickListener<User>() {

                    @Override
                    public void onItemClick(int i, User user) {
                        if (user.getId() == Storage.getId()) {
                            finish();
                        } else {
                            Bundle bundle = new Bundle();
                            bundle.putString("mobile", user.getMobile());
                            startActivity(LoginActivity.class, bundle);
                            finish();
                            AppManager.getAppManager().finish(MainActivity.class);
                        }
                    }
                }).build();
        mHelper.init();
        mHelper.notifyAdapter(Storage.getUserList());
    }

    @OnClick(R.id.switch_user_quit)
    public void onViewClicked() {
        finish();
    }
}
